package com.ruoyi.web.controller.app;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.WcPatentApplication;
import com.ruoyi.system.domain.WcPatentApplicationAncillary;
import com.ruoyi.system.domain.vo.business.*;
import com.ruoyi.system.dto.coopHan.PageCulvertNoticeDto;
import com.ruoyi.system.dto.handleRecord.IdSearchVO;
import com.ruoyi.system.service.IWcPatentApplicationAncillaryService;
import com.ruoyi.system.service.IWcPatentApplicationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 剧本备案申请Controller
 *
 * @author ruoyi
 * @date 2024-02-28
 */
@Controller
@Api(tags = {"(app)剧本备案申请"})
@RequestMapping("app/system/wcPatentApplication")
public class AppWcPatentApplicationController extends BaseController {

    @Autowired
    private IWcPatentApplicationService service;

    @Autowired
    private IWcPatentApplicationAncillaryService ancillaryService;

    /**
     * 查询剧本备案申请列表
     */
    @ApiOperation("查询剧本备案申请列表")
    //@RequiresPermissions("system:application:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WcPatentApplicationSelectListDto dto) {
        startPage();
        Page<WcPatentApplicationSelectListVO> list = service.list(dto);
        return getDataTable(list.getRecords());
    }

    /**
     * 修改保存剧本备案申请
     */
    @ApiOperation("修改剧本备案申请")
    //@RequiresPermissions("system:application:edit")
    @Log(title = "剧本备案申请", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult<String> editSave(@RequestBody WcPatentApplicationUpdateVO wcPatentApplication) throws Exception {
        return success(service.updateSave(wcPatentApplication));
    }


    /**
     * 新增保存剧本备案申请
     */
    @ApiOperation("(app)新增剧本备案申请")
    //@RequiresPermissions("system:application:add")
    @Log(title = "(app)剧本备案申请", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult<String> addSave(@RequestBody WcPatentApplicationSaveVO saveVO) throws Exception {
        return success(service.addSave(saveVO));
    }

    /**
     * 剧本备案申请详情
     */
    @ApiOperation("剧本备案申请详情")
    //@RequiresPermissions("system:application:edit")
    @GetMapping("/getById/{id}")
    @ResponseBody
    public AjaxResult<WcPatentApplicationDetailVO> edit(@PathVariable("id") Long id) {
        WcPatentApplicationDetailVO vo = service.selectWcPatentApplicationDetailVOById(id);
        return success(vo);
    }

    /**
     * 剧本备案申请详情
     */
    @ApiOperation("剧本备案公示列表")
    //@RequiresPermissions("system:application:edit")
    @PostMapping("/pageList")
    @ResponseBody
    public AjaxResult<Page<WcPatentApplicationSelectListVO>> pageList(@RequestBody PageCulvertNoticeDto dto) {
        Page<WcPatentApplicationSelectListVO> wcPatentApplicationSelectListVOPage = service.pageNotice(dto);
        return success(wcPatentApplicationSelectListVOPage);
    }
    @ApiOperation("删除剧本备案申请")
    //@RequiresPermissions("system:application:remove")
    @Log(title = "剧本备案申请", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Long id) {
        boolean b = service.removeById(id);
        //附件一块删除
        ancillaryService.remove(Wrappers.lambdaQuery(WcPatentApplicationAncillary.class).
                eq(WcPatentApplicationAncillary::getWcPatentApplicationId,id));
        return toAjax(b);
    }


    /**
     * 新增保存剧本备案申请
     */
    @ApiOperation("【新】查询反馈国家电影局信息")
    @GetMapping("/get_recommendation")
    public AjaxResult<List<WcPatentApplicationRecommendationVO>> get_recommendation( @ApiParam(value = "查询参数") @ModelAttribute IdSearchVO saveVO) throws Exception {
        return AjaxResult.success(service.getRecommendationList(saveVO));
    }


}
